//
//  JWTCalendar.m
//  JWT
//
//  Created by ndm on 17/2/9.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTCalendar.h"

@implementation JWTCalendar

SHARED_INSTANCE_IMPLEMENTATION(JWTCalendar);

/**
 日期转日历
 */
-(NSArray *) calendarFromDate{
    //获取日期
    NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];
    //获取当前日期
    NSDate *date0 = [NSDate date];
    //获取明天日期
    NSDate *date1 = [NSDate dateWithTimeInterval:86400 sinceDate:date0];
    //获取后天日期
    NSDate *date2 = [NSDate dateWithTimeInterval:86400 sinceDate:date1];
    
    NSDate *date3 = [NSDate dateWithTimeInterval:86400 sinceDate:date2];
    NSDate *date4 = [NSDate dateWithTimeInterval:86400 sinceDate:date3];
    NSDate *date5 = [NSDate dateWithTimeInterval:86400 sinceDate:date4];
    NSDate *date6 = [NSDate dateWithTimeInterval:86400 sinceDate:date5];
    
    
    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    //设置时区
    calendar.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ZH_cn"];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear |
    NSCalendarUnitMonth |
    NSCalendarUnitDay |
    NSCalendarUnitWeekday |
    NSCalendarUnitHour |
    NSCalendarUnitMinute |
    NSCalendarUnitSecond;
    
    comps = [calendar components:unitFlags fromDate:date0];
    NSInteger week0 = [comps weekday];
    NSInteger year0 =[comps year];
    NSInteger month0 = [comps month];
    NSInteger day0 = [comps day];
    NSString *str0 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month0,day0,[arrWeek objectAtIndex:(week0 - 1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year0,month0,day0]];
    
    comps = [calendar components:unitFlags fromDate:date1];
    NSInteger week1 = [comps weekday];
    NSInteger year1=[comps year];
    NSInteger month1 = [comps month];
    NSInteger day1 = [comps day];
    NSString *str1 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month1,day1,[arrWeek objectAtIndex:(week1 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year1,month1,day1]];
    
    comps = [calendar components:unitFlags fromDate:date2];
    NSInteger week2 = [comps weekday];
        NSInteger year2=[comps year];
    NSInteger month2 = [comps month];
    NSInteger day2 = [comps day];
    NSString *str2 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month2,day2,[arrWeek objectAtIndex:(week2 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year2,month2,day2]];
    
    comps = [calendar components:unitFlags fromDate:date3];
    NSInteger week3 = [comps weekday];
    NSInteger year3=[comps year];
    NSInteger month3 = [comps month];
    NSInteger day3 = [comps day];
    NSString *str3 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month3,day3,[arrWeek objectAtIndex:(week3 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year3,month3,day3]];
    
    comps = [calendar components:unitFlags fromDate:date4];
    NSInteger week4 = [comps weekday];
    NSInteger year4=[comps year];
    NSInteger month4 = [comps month];
    NSInteger day4 = [comps day];
    NSString *str4 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month4,day4,[arrWeek objectAtIndex:(week4 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year4,month4,day4]];
    
    comps = [calendar components:unitFlags fromDate:date5];
    NSInteger week5 = [comps weekday];
    NSInteger year5 =[comps year];
    NSInteger month5 = [comps month];
    NSInteger day5 = [comps day];
    NSString *str5 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month5,day5,[arrWeek objectAtIndex:(week5 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year5,month5,day5]];
    
    comps = [calendar components:unitFlags fromDate:date6];
    NSInteger week6 = [comps weekday];
    NSInteger year6 =[comps year];
    NSInteger month6 = [comps month];
    NSInteger day6 = [comps day];
    NSString *str6 = [NSString stringWithFormat:@"%zi.%zi,%@,%@",month6,day6,[arrWeek objectAtIndex:(week6 -1)],[NSString stringWithFormat:@"%zi-%zi-%zi",year6,month6,day6]];
    
    
    NSLog(@"%@    %@     %@       %@    %@     %@  %@",str0,str1,str2,str3,str4,str5,str6);
    return @[str0,str1,str2,str3,str4,str5,str6];
}

@end
